/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Model;

import Common.Constant;
import Helper.UserHelper;
import java.util.ArrayList;
import javax.swing.table.AbstractTableModel;

/**
 *
 * @author KIENLT
 */
public class UserModel extends AbstractTableModel{

    ArrayList<UserHelper> UserList;
    
    private final String colunmsName[] = { Constant.getBundle().getString("Id"), Constant.getBundle().getString("Username"), Constant.getBundle().getString("Phone"), Constant.getBundle().getString("Email"), Constant.getBundle().getString("Roles") };
    private final Class columnsClass[] = { String.class, String.class, String.class, String.class, String.class };
    
    public UserModel(ArrayList<UserHelper> UserList){
        this.UserList = UserList;
    }
    
    @Override
    public int getRowCount() {
        return UserList.toArray().length;
    }

    @Override
    public int getColumnCount() {
        return colunmsName.length;
    }

    @Override
    public Object getValueAt(int rowIndex, int columnIndex) {
        switch(columnIndex){
            case 0 : 
                return UserList.get(rowIndex).getId();
            case 1 : 
                return UserList.get(rowIndex).getUserName();
            case 2 :
                return UserList.get(rowIndex).getPhone();
            case 3 :
                return UserList.get(rowIndex).getEmail();
            case 4 :
                return UserList.get(rowIndex).getRoles();
            default: 
                return null;
        }
    }
    
    @Override
    public String getColumnName(int icol){
        return colunmsName[icol];
    }
    
    @Override
    public Class getColumnClass(int icol){
        return columnsClass[icol];
    }
    
}
